package lanou.giftsay_01.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import lanou.giftsay_01.R;
import lanou.giftsay_01.bean.NormalBean;

/**
 * Created by dllo on 16/8/22.
 */
public class FenggeRvAdapter extends RecyclerView.Adapter<FenggeRvAdapter.MyViewHoler> {
    private Context context ;
    private NormalBean normalBean ;
    private int tag ;

    public void setTag(int tag) {
        this.tag = tag;
    }

    public void setNormalBean(NormalBean normalBean) {
        this.normalBean = normalBean;
        notifyDataSetChanged();
    }

    public FenggeRvAdapter(Context context) {
        this.context = context;
    }

    @Override
    public MyViewHoler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_fengge_rv  ,parent ,false);
        MyViewHoler  myViewHoler = new MyViewHoler(view);

        return myViewHoler;
    }

    @Override
    public void onBindViewHolder(MyViewHoler holder, int position) {

        Picasso.with(context).load(normalBean.getData().getChannel_groups().get(tag).getChannels().get(position).getCover_image_url()).into(holder.iv);
    }

    @Override
    public int getItemCount() {
        return  normalBean!= null ? normalBean.getData().getChannel_groups().get(tag).getChannels().size() : 0;
    }

    public class MyViewHoler extends RecyclerView.ViewHolder {
        ImageView iv ;
        public MyViewHoler(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.iv_fengge_item);
        }
    }
}
